package com.zb.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjCustomerInfo;
import com.zb.mapper.ZjCustomerInfoMapper;
import com.zb.service.ZjCustomerInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 商家信息表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-07-18
 */
@Service
public class ZjCustomerInfoServiceImpl extends ServiceImpl<ZjCustomerInfoMapper, ZjCustomerInfo> implements ZjCustomerInfoService {
    @Resource
    private ZjCustomerInfoMapper customerInfoMapper;

    @Override
    public void save(Long id) {
        ZjCustomerInfo info = new ZjCustomerInfo();
        info.setId(id);
        info.setAmountBalance(new BigDecimal("0.0"));
        info.setSmsBalance(0);
        info.setVersionId(0L);
        info.setVersion("");
        info.setUsers(0);
        this.save(info);
    }

    // 根据ID更新短信数量
    @Override
    public void updateSmsBalanceById(Long id, int count) {
        customerInfoMapper.updateSmsBalanceById(id, count);
    }

    // 根据商家ID检查短信是否充足
    @Override
    public boolean isSmsAbundant(Long id) {
//        Integer smsBalanceCount = customerInfoMapper.getSmsBalanceCountById(id);
//        return null != smsBalanceCount && (smsBalanceCount == -1 || smsBalanceCount > 0);
        return true;
    }
}
